package com.ddhcodeduck.common.enums;

import lombok.Getter;
import lombok.experimental.UtilityClass;

/**
 * 题目难度枚举类
 */
@Getter
public enum QuestionDifficulty {
    /**
     * 简单
     */
    EASY(0, "简单"),
    /**
     * 中等
     */
    MEDIUM(1, "中等"),
    /**
     * 困难
     */
    HARD(2, "困难");

    private final Integer code;
    private final String name;

    QuestionDifficulty(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    // 根据 code 获取对应的枚举值
    public static QuestionDifficulty fromCode(Integer code) {
        for (QuestionDifficulty difficulty : QuestionDifficulty.values()) {
            if (difficulty.getCode().equals(code)) {  // 使用 equals 方法进行比较
                return difficulty;
            }
        }
        throw new IllegalArgumentException("非法的code: " + code);
    }
}
